﻿using System;
using System.Data.OleDb;
using TheOutLetLibrary.Dominio;

namespace TheOutLetLibrary.Infraestrutura {

    public class Accessk_deliveryDAO: BaseDAO, IGenericDAO<k_delivery> {

        public Accessk_deliveryDAO(OleDbTransaction transacao)
            : base(transacao) {
        }

        public int Inclua(k_delivery entity) {

            OleDbCommand comando = GetCommand();

            comando.CommandText =
                " INSERT INTO k_delivery (" +
                " NR_PEDIDO, deliveryType, estimate, price, trackingCode) " +
                " VALUES (" +
                " @NR_PEDIDO, @deliveryType, @estimate, @price, @trackingCode)";

            comando.Parameters.Add("@NR_PEDIDO", OleDbType.Integer).Value = entity.NR_PEDIDO;
            comando.Parameters.Add("@entityType", OleDbType.VarChar).Value = entity.deliveryType;
            comando.Parameters.Add("@estimate", OleDbType.VarChar).Value = entity.estimate.ToString("s");
            comando.Parameters.Add("@price", OleDbType.VarChar).Value = entity.price.ToString();
            comando.Parameters.Add("@trackingCode", OleDbType.VarChar).Value = entity.trackingCode;
            comando.ExecuteNonQuery();

            comando.CommandText = "SELECT @@IDENTITY";
            entity.COD = Convert.ToInt32(comando.ExecuteScalar());
            return entity.COD;

        }

        public k_delivery Ache(int Id) {
            throw new NotImplementedException();
        }
    }
}
